function update_time_avg_stats()
% Funcion:   update_time_avg_stats
% Proposito: Actualiza los acumuladores estadisticos para las 
%            areas en el calculo de tiempos medios
%
global Q_LIMIT;
	global BUSY;
	global IDLE;
	global INFINITY;

	global next_event_type;
	global num_custs_delayed;
	global num_delays_required;
	global num_events;
	global num_in_q;
	global server_status;

	global arrivals_mean;
	global client_times;

	%Variables de la UI
	global ui_queue_len;
	global ui_status;
	global ui_mean;

	global ui_serving;
	%% Variables de tiempos de servicio

	%Variables de las ERs
	global er_queue_len;
	global er_status;
	global er_next_event;
	global er_next_free;
	global er_mean;
	global num_er_busy;

	global er_queue;
	global er_queue_index;
	global er_queue_last;
	global er_queue_max_items;
	global er_serving;
	%% Variables de tiempos de servicio

	%Variables de la ST
	global st_queue_len;
	global st_status;
	global st_mean;
	global st_pass;

	%%QUEUE
	global st_queue;
	global st_queue_index;
	global st_queue_last;
	global st_queue_max_items;
	global st_serving;
	%% Variables de tiempos de servicio

	global time;
	global num_arrivals;
	global time_arrival;
	global time_last_event;
	global time_next_event;
	global total_of_delays;

	%Estadisticas
	global area_ui_queue;
	global area_er_queue;
	global area_st_queue;

	global area_ui_status;
	global area_er1_status;
	global area_er2_status;
	global area_er3_status;
	global area_st_status;

	global queue_lengths_vec;

% Computa el tiempo desde el ultimo evento
% y actualiza el markador de teiempo del
% ultimo evento.
time_since_last_event = time - time_last_event;
time_last_event       = time;

% Actualiza el area bajo la curva de numero en cola
%area_num_in_q = area_num_in_q + num_in_q * time_since_last_event;

% Actualiza el area bajo la curva de la funcio de servidor-ocupado
%area_server_status = area_server_status + server_status * time_since_last_event;

%Actualizo la long de colas y estado.
area_ui_queue = area_ui_queue + ui_queue_len*time_since_last_event;
area_er_queue = area_er_queue + er_queue_len*time_since_last_event;
area_st_queue = area_st_queue + st_queue_len*time_since_last_event;

area_ui_status = area_ui_status + ui_status*time_since_last_event;
area_er1_status = area_er1_status + (er_serving(1) && 1)*time_since_last_event;
area_er2_status = area_er2_status + (er_serving(2) && 1)*time_since_last_event;
area_er3_status = area_er3_status + (er_serving(3) && 1)*time_since_last_event;
area_st_status = area_st_status + st_status*time_since_last_event;

%Vector de longitudes de colas
queue_lengths_vec = [queue_lengths_vec;time,ui_queue_len,er_queue_len,st_queue_len];


return;
